import request from '@/utils/request'

/**
 * 获取用户书架列表
 * @param page 页码
 * @param ipp 每页条数
 */
export function getBookShelf(
  page: number = 1,
  ipp: number = 10,
): Promise<{
  objects: BookDetail[]
}> {
  return request({
    url: `/wordsapp/user_material_books?ipp=${ipp}&page=${page}&book_category=OFFICIAL`,
    method: 'get',
  })
}

export interface BookDetail {
  materialbook: {
    description: '一轮复习必背！26考研英语大纲词表全收录，英语一英语二通用' //书本描述
    icon_url: 'https://media-image1.baydn.com/wordmaster_pub_image/tkdghk/c557f4220d99988d6f880ecea2499b31.2cd35704578ee1353c13101a672abbcc.jpg?x-oss-process=image/quality,Q_80' //书本封面
    id: 'rhhhu' //书本ID
    name: '完全版考研考纲词汇(乱序)' //书本名称
    total_count: 5561 //书本总词数
  }
  created_at: '2025-09-07T00:28:11.512483+00:00' //创建时间
  updated_at: '2025-09-07T00:28:11.512483+00:00' //更新时间
  finished_count: 0 //完成数量
}

/**
 * 获取该书本ID未学习的单词列表
 * @param bookId 书本ID
 * @param page 页码
 * @param ipp 每页条数
 * @returns
 */
export function getUnlearnedWords(
  bookId: string,
  page: number = 1,
  ipp: number = 20,
): Promise<UnlearnedWordsResponse> {
  return request({
    url: `/wordsapp/user_material_books/${bookId}/learning/words/unlearned_items?ipp=${ipp}&page=${page}`,
    method: 'get',
  })
}

/**
 * 单词详情接口
 */
export interface WordDetail {
  vocabulary_id: string
  word: string
  senses: Array<{
    definition_cn: string //中文释义
    definition_en: string //英文释义
    pos: string //词性
  }>
}
/**
 * 获取未学习单词列表的响应接口
 */
export interface UnlearnedWordsResponse {
  ipp: number
  objects: Array<{
    vocab_with_senses: WordDetail
  }>
  total: number
  page: number
}

/**
 * 标记以下单词为简单词
 */
export function markWordsAsEasy(bookId: string, wordIds: string[]): Promise<void> {
  return request({
    url: `/wordsapp/user_material_books/${bookId}/learning/words/simple_learned_items`,
    method: 'post',
    data: {
      action: 1,
      item_ids: wordIds,
    },
  })
}
